import os

import jaydebeapi
import yaml
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/ya/')
def read_yaml():
    with open('config.yaml') as f:
        config_data = yaml.load(f, Loader=yaml.FullLoader)
    return str(config_data)


sql='desc formatted t_rk_jbxx'
def get_jar():
    DIR = './tlib/'
    jarFile = []
    for i in os.listdir(DIR):
        jarFile.append(DIR+i)
    return jarFile

@app.route('/hive/')
def connect():
    url = 'jdbc:hive2://bigdata107.depts.bingosoft.net:22107/user05_db'
    user = 'user05'
    password = 'pass@bingo5'
    dirver = 'org.apache.hive.jdbc.HiveDriver'
    jarFile = get_jar()
    conn = jaydebeapi.connect(dirver, url, [user, password], jarFile)
    curs = conn.cursor()
    curs.execute(sql)
    result = curs.fetchall()
    print(result)
    curs.close()
    conn.close()
    return (str(result))

if __name__ == '__main__':
    app.run()
